#ifndef DOWNLOAD_FILE_H
#define DOWNLOAD_FILE_H

#include <QObject>
#include <QtNetwork>
#include <QAbstractSocket>
#include <QTcpSocket>

#include <QFile>
#include <QFileDialog>

#include <QDateTime>
#include <QDataStream>

#include "../sql.h"

class download_file : public QObject
{
    Q_OBJECT
public:
    explicit download_file(QObject *parent = nullptr);

    /**
     * @brief startListen 启动监听
     * @param port
     */
    void startListen(unsigned short port);

    /**
     * @brief recvFile 接收文件函数
     */
    void recvFile();

signals:
    //接收完毕
    void recvOver();

private:
    QTcpServer *fileserver;
    QTcpSocket *filesocket;

    QFile file;
    qint64 filesize = 0;//文件大小
    QString filename;

    qint64 recvfilesize = 0;//已接收大小
    bool isStart;//接收头部标记

    sql* mysql = nullptr;
};

#endif // DOWNLOAD_FILE_H
